package vip.george.cartoon;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.util.StringUtils;
import vip.george.animal.Cat;
import vip.george.animal.Mouse;

import java.util.Objects;


//@Component
@EnableConfigurationProperties(CartoonProperties.class)
public class CartoonMovie {


    private Cat cat;

    private Mouse mouse;



    public CartoonMovie(CartoonProperties cartoonProperties) {
        this.cat = new Cat();
        cat.setName(Objects.nonNull(cartoonProperties.getCat()) && StringUtils.hasText(cartoonProperties.getCat().getName()) ? cartoonProperties.getCat().getName() : "tom");
        cat.setAge(Objects.nonNull(cartoonProperties.getCat()) && Objects.nonNull(cartoonProperties.getCat().getAge()) && cartoonProperties.getCat().getAge() > 0 ? cartoonProperties.getCat().getAge() : 4);
        this.mouse = new Mouse();
        mouse.setName(Objects.nonNull(cartoonProperties.getMouse()) && StringUtils.hasText(cartoonProperties.getMouse().getName()) ? cartoonProperties.getMouse().getName() : "jerry");
        mouse.setAge(Objects.nonNull(cartoonProperties.getMouse()) && Objects.nonNull(cartoonProperties.getMouse().getAge()) && cartoonProperties.getMouse().getAge() > 0 ? cartoonProperties.getMouse().getAge() : 1);
    }


    public void play() {


        System.out.println(cat.getAge()+"岁的"+ cat.getName() +"和"+ mouse.getAge()+"岁的"+ mouse.getName()+"正在玩耍。。。");
    }




}
